package gui;

import game.GameManager;

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextArea;

@SuppressWarnings("serial")
public class GamePlayPanel extends JFrame implements GameManagerChanged{
	private GameManager manager;
	private JPanel root;
	public GamePlayPanel(GameManager waitingManager) {
		super("Texas Hold'em");
		setSize(new Dimension(500,500));
		root = new JPanel();
		root.setLayout(new BoxLayout(root,BoxLayout.Y_AXIS));
		add(root);
		manager = waitingManager;
		manager.setChangeListener(this);
		guiLayout();
		setVisible(true);
	}
	public void guiLayout(){
		root.removeAll();
		JTextArea text = new JTextArea(manager.gameString());
		System.out.print("GameState:"+manager.gameString());
		root.add(text);
		JButton check = new JButton("Check or Call");
		check.addActionListener(new ActionListener(){

			@Override
			public void actionPerformed(ActionEvent e) {
				manager.checkOrCall();
			}
			
		});
		root.add(check);
		JButton raise = new JButton("Call and raise by 50");
		
		raise.addActionListener(new ActionListener(){

			@Override
			public void actionPerformed(ActionEvent e) {
				manager.raise(50);
			}
			
		});
		root.add(raise);
		JButton fold = new JButton("Fold");
		fold.addActionListener(new ActionListener(){

			@Override
			public void actionPerformed(ActionEvent e) {
				manager.fold();
			}
			
		});
		root.add(fold);
		System.out.println("GUI Displayed");
		root.revalidate();
		root.repaint();
		
	}
	@Override
	public void gameManagerChanged() {
		guiLayout();
	}

	
}
